package com.estar.integaration.Config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//开启swagger
@EnableSwagger2      /*   :/swagger-ui.html    */
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket getDocket(Environment environment){

        //设置在生产环境下才开启swagger
        Profiles profiles = Profiles.of("dev");
        boolean flag = environment.acceptsProfiles(profiles);

        /**
         * 配置文档信息
         */
        return  new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                //是否启用swagger
                .enable(flag)
                .select()
                //basePackage:指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.smart.smartdustbin.Controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("swagger文档")
                .version("1.0")
                .build();
    }

}
